package com.zyw.zhuangdian.dao.impl;

import com.zyw.zhuangdian.dao.BaseDao;
import com.zyw.zhuangdian.dao.ProductionDao;
import com.zyw.zhuangdian.exceptions.MyDaoException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Repository
@Transactional
public class ProductionDaoImpl extends BaseDao implements ProductionDao {
    @Override
    public void addProduction(Map in) {
        int i = sqlTemplate.insert("ProductionDaoImpl.addProduction",in);
        if (i<1){
            throw new MyDaoException("插入产品记录失败");
        }
    }

    @Override
    public void updateProduction(Map in) {
        int i = sqlTemplate.update("ProductionDaoImpl.updateProduction",in);
        if (i<1){
            throw new MyDaoException("更新产品记录失败");
        }
    }

    @Override
    public List<Map> listProductions(Map in) {
        List<Map> list = sqlTemplate.selectList("ProductionDaoImpl.listProductions",in);
        return list;
    }

    @Override
    public int listProductionsCount(Map in) {
        List<Map> list = sqlTemplate.selectList("ProductionDaoImpl.listProductionsCount",in);
        if (list.size() < 1){
            return 0;
        }
        return Integer.parseInt(list.get(0).get("count").toString());
    }
}
